package com.bvgol.examples.my;/**
 * @Classname EnumTest
 * @Description TODO
 * @Date 2021/12/29 9:53
 * @Created by GUOCHEN
 */

import lombok.Data;

import java.util.Arrays;
import java.util.stream.Collectors;

/**
 * @program: my-spring-completely
 * @description:
 * @author: GUOCHEN
 * @create: 2021/12/29 09:53
 */
public class EnumTest {
    public static void main(String[] args) {
        SubmitOrderResponseVo vo = new SubmitOrderResponseVo();
        vo.setCode(1);
        String msg = vo.getMsg();
        System.out.println("msg = " + msg);
    }
}
@Data
class SubmitOrderResponseVo {

    /**
     * 错误状态码
     **/
    private Integer code;

    private String msg;

    public String getMsg() {
        return Arrays.stream(SubmitOrderStatusEnum.values()).collect(Collectors.toMap(SubmitOrderStatusEnum::getCode, o -> o)).get(code).getMsg();
    }
}
 enum SubmitOrderStatusEnum {
    SUCCESS(0,"下单成功"),
    FAIL_TOKEN(1,"下单失败,令牌订单信息过期，请刷新再次提交!"),
    FAIL_COMPUTER_PRICE(2,"下单失败,订单商品价格发生变化，请确认后再次提交!"),
    FAIL_LOCK_WARE(3,"下单失败,库存锁定失败，商品库存不足!"),
    FAIL_EXCEPTION(4,"下单失败,出现异常!");

    private Integer code;
    private String msg;

    SubmitOrderStatusEnum(Integer code, String msg) {
        this.code = code;
        this.msg = msg;
    }
    public Integer getCode() {
        return code;
    }

    public String getMsg() {
        return msg;
    }
}
